const app = getApp()
import {
  showMsg
} from '../../../../utils/config.js'
import {
  reqConsumerHomeList
} from '../../../../request/api.js';
Page({
  data: {
    navHeight: app.globalData.navHeight + 'px', //头部距离
    bottomHeight: app.globalData.bottomHeight + 'px', //iphone底部距离

    dataList: []
  },

  onLoad(options) {
    this.getDataList()
  },


  onShow() {},

  async getDataList() {
    let params = {
      userId: app.globalData.userId,
    }
    const res = await reqConsumerHomeList(params)
    if (res.code !== 20000) return showMsg(res.message)
    let {
      rows
    } = res.data
    this.setData({
      dataList: rows || []
    })

  },

  goCreate() {
    const _this = this
    wx.navigateTo({
      url: '/packageC/pages/family/add/add',
      events: {
        receiveDataFromDetail: function (res) {
          if (res.isUpdataList) {
            _this.getDataList()
          }
        },
      },
    })
  },

  goDetail(e) {
    const _this = this
    const {
      item
    } = e.currentTarget.dataset
    wx.navigateTo({
      url: '/packageC/pages/family/detail/detail',
      events: {
        receiveDataFromDetail: function (res) {
          if (res.isUpdataList) {
            _this.getDataList()
          }
        },
      },
      success: function (res) {
        res.eventChannel.emit('sendDataToDetail', {
          data: item
        })
      }
    })
  }

})